﻿<cfsilent>
	<cfsetting requesttimeout="300" />
	<cfflush interval="1024" />
	<cfscript>
		
		temFile = GetTempDirectory() & createUUID() & ".xls";

		studentUpdate = 0;
		studentInsert = 0;
		
		targetArgs = structNew();
		structInsert(targetArgs, "TabID", "labImport", true);
		
		studentAdvice = getProperty("serviceFactory").getBean("studentPropertyAdvice");
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");
		
		sequenceMatrixGroupUser = getProperty("serviceFactory").getBean("sequenceMatrixGroupUser");
		
		chsFactory = getProperty("serviceFactory").getBean("chineseFactory");
		
		logFactory = getProperty("serviceFactory").getBean("logFactory");
		
	</cfscript>
</cfsilent>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>导入学籍数据</title>
<link href="<cfoutput>#getProperty('cdnServer')#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/css/impoter.css" rel="stylesheet" type="text/css">
</head>

<body>

	<cfif isDefined("FORM.upload")>
		
		<!--- 将文件保存至临时目录 --->
		<cftry>
			<cffile action="upload" fileField="upload" destination="#temFile#" nameconflict="overwrite">
			<cfcatch type="application">
				<p class="error">上传的文件类型不正确, 请使用电子表格作为数据导入文件.</p>
			</cfcatch>
		</cftry>
		
		<!--- 将文件转换为电子表格对象 --->
		<cfif fileExists(temFile)>
			<cftry>
				<cfspreadsheet action="read" src="#temFile#" excludeHeaderRow="true" headerrow="1" query="rs" sheetname="学生基础信息">
				<cfcatch type="application">
					<p class="error">电子表格文件格式不正确, 请使用下载的模板文件录入学籍信息</p>
				</cfcatch>
			</cftry>
			
			<!--- 文件已成功转换为查询对象 --->
			<cfif isDefined("rs") and isQuery(rs)>

				<p class="success">尝试读取电子表格数据 ... 完成</p>
				
				<!--- 检查必要数据字段 --->
				<cfset columnChecked = true />
				<cfif not listFindNoCase(rs.columnList, "学号")><cfset columnChecked = false /></cfif>
				<cfif not listFindNoCase(rs.columnList, "护照名")><cfset columnChecked = false /></cfif>
				<cfif not listFindNoCase(rs.columnList, "性别")><cfset columnChecked = false /></cfif>
				<cfif not listFindNoCase(rs.columnList, "护照号")><cfset columnChecked = false /></cfif>
				<cfif not listFindNoCase(rs.columnList, "国籍")><cfset columnChecked = false /></cfif>
				
				<cfif not columnChecked>
					<p class="error">电子表格数据列不完整, 请检查模板文件是否包含以下必须字段信息: 学号,护照名,性别,护照号,国籍,学生类型</p>
				</cfif>

				<cfif columnChecked>

					<p class="success">正在检查数据子项 ... 完成</p> 
				
					<cftransaction>
					
						<cfloop query="rs">
							
							<!--- 初始化学生学籍性质 --->
							<cfset propAdvice = studentAdvice.init() />
							
								
							<!--- 检查国籍是否正确 --->
                                   <cfset sql = "SELECT code_id FROM i_code_info WHERE name = :countryName AND field_id = '2' " /> 
                                   
                                   <cfset queryObj = new Query( datasource=application.dnsMaster ) />
                                   
                                   <cfset queryObj.addParam( name="countryName", value=rs["国籍"][rs.currentRow], cfsqltype="cf_sql_varchar" ) /> 
                                   
                                   <cfset rs_country = queryObj.execute( sql=sql ).getResult() />  
                                   
                                   <cfif rs_country.recordCount eq 1>
                         
                                             <!--- 检查护照是否正确 --->
                                             <cfif len(rs["护照号"][rs.currentRow])>
                                             
                                                       <!--- 关键字段检查完毕 --->
                                                       <!--- 检查学生信息是否存在--->
                                                       <cfset sql = "SELECT STU_NAME_ENGLISH, stu_name_used FROM t_student WHERE stu_id = :studentId" />

                                                       <cfset queryObj = new Query( datasource=application.dnsMaster ) />
                                                       <cfset queryObj.addParam( name="studentId", value=trim(rs["学号"][rs.currentRow]), cfsqltype="cf_sql_varchar" ) />
                                                       
                                                       <cfset rs_student = queryObj.execute( sql=sql ).getResult() />
                                                       
                                                       <cfif rs_student.recordCount eq 0>
                                                                 
                                                                 <!---<cfset stuType = rs_stuType.code_id />--->
                                                                 
                                                                 <!---教师导入学生默认为普通进修生--->
                                                                 <cfset stuType = "53" />
                                                                 
                                                                 <!--- 设置学生档案基础信息 --->
                                                                 <cfset studentName = rs["护照名"][rs.currentRow] />
                                                                 <cfset stuNameEnglish = rs["护照名"][rs.currentRow] />
                                                                 <cfset sex = "2" />
                                                                 
                                                                 <cfif rs["性别"][rs.currentRow] eq "男">
                                                                           <cfset sex = "1" />
                                                                 </cfif>
                                                                 
                                                                 <cfset idCard = rs["护照号"][rs.currentRow] />
     
                                                                 <cfset birthday = "" />
                                                                                                                   
                                                                 <!--- 
                                                                      $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
                                                                      可选属性 
                                                                      $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
                                                                 --->
                                                                 
                                                                  <!--- 中文名 --->
                                                                 <cfif listFindNoCase(rs.columnList, "中文名") and len(rs["中文名"][rs.currentRow])>
                                                                      <cfset studentName = rs["中文名"][rs.currentRow] />
                                                                 </cfif>
                                                       
                                                                 <!--- 出生日期 --->
                                                                 <cfif listFindNoCase(rs.columnList, "出生日期") and len(rs["出生日期"][rs.currentRow])>
                                                                      <cfset birthday = left(rs["出生日期"][rs.currentRow],4) & "-" & mid(rs["出生日期"][rs.currentRow],5,2) & "-" & right(rs["出生日期"][rs.currentRow],2) />
                                                                 </cfif>
                                                                 
                                                               
                                                             
                                                                 <cfset studentInsert++ />
                                                                 
                                                                 <cfset sql = "INSERT INTO t_student (
                                                                                          stu_id, cls_id, stu_name,
                                                                                          stu_pyidx, stu_name_english, stu_name_used,
                                                                                          stu_sex, stu_birthday, idtype,
                                                                                          stu_idcard, area_code ,pa_code,
                                                                                          nation_code, sbj_direction, 
                                                                                          nationality, continent, stu_type, class_id, tch_id  
                                                                                     )VALUES(
                                                                                          :studentId, :classId, :studentName, 
                                                                                          :pinyin, :englishName, :usedName, 
                                                                                          :sex, :birthday, :idType, 
                                                                                          :idCard, :areaCode, :politicalStatus, 
                                                                                          :nationCode, :subjectDirection , 
                                                                                          :nationality, :continent, :stuType, :clsId, :tchId 
                                                                                     )" /> 
                                                                 
                                                                 <cfset queryObj = new Query( datasource=application.dnsMaster ) />
                                                                 
                                                                 <cfset queryObj.addParam( name="studentId", value=trim(rs["学号"][rs.currentRow]), cfsqltype="cf_sql_varchar" ) /> 
                                                                 <cfset queryObj.addParam( name="classId", value='', cfsqltype="cf_sql_varchar" ) /> 
                                                                 <cfset queryObj.addParam( name="studentName", value=studentName, cfsqltype="cf_sql_varchar" ) /> 
                                                                 <cfset queryObj.addParam( name="pinyin", value="xxx", cfsqltype="cf_sql_varchar" ) /> 
                                                                 <cfset queryObj.addParam( name="englishName", value=stuNameEnglish, cfsqltype="cf_sql_varchar" ) /> 	
                                                                 <cfset queryObj.addParam( name="usedName", value="", cfsqltype="cf_sql_varchar" ) />                                                                     
                                                                 <cfset queryObj.addParam( name="sex", value=sex, cfsqltype="cf_sql_char" ) /> 
                                                                 <cfset queryObj.addParam( name="birthday", value=birthday, cfsqltype="cf_sql_char" ) /> 
                                                                 <cfset queryObj.addParam( name="idType", value='02', cfsqltype="cf_sql_char" ) /> 
                                                                 <cfset queryObj.addParam( name="idCard", value=idCard, cfsqltype="cf_sql_varchar" ) /> 
                                                                 <cfset queryObj.addParam( name="areaCode", value='511000', cfsqltype="cf_sql_char" ) /> 
                                                                 <cfset queryObj.addParam( name="politicalStatus", value='13', cfsqltype="cf_sql_char" ) /> 
                                                                 <cfset queryObj.addParam( name="nationCode", value='01', cfsqltype="cf_sql_char" ) /> 
                                                                 <cfset queryObj.addParam( name="subjectDirection", value="0", cfsqltype="cf_sql_char" ) /> 
                                                                 <cfset queryObj.addParam( name="nationality", value=rs["国籍"][rs.currentRow], cfsqltype="cf_sql_varchar" ) />
                                                                 <cfset queryObj.addParam( name="continent", value="", cfsqltype="cf_sql_varchar" ) />
                                                                 <cfset queryObj.addParam( name="stuType", value=stuType, cfsqltype="cf_sql_varchar" ) />
                                                                 <cfset queryObj.addParam( name="clsId", value='', cfsqltype="cf_sql_varchar" ) />
                                                                 <cfset queryObj.addParam( name="tchId", value='', cfsqltype="cf_sql_varchar" ) />
                           
                                                                 <cfset queryObj.execute( sql=sql ) />
                                                                      
                                                                   
                                                       
                                                                 <!--- 处理学籍数据 --->
                                                       
                                                                 <!--- 新学籍基础数据 --->
                                                                 <cfset academicType = 1 />
                                                                 <cfset statusCode = "01" /> 
                                                                 
                                                                 <cfset propAdvice.setRecognized(true) /><!--- 是否有学籍 --->
                                                                 <cfset propAdvice.setRegister(true) /><!--- 是否电子注册 --->
                                                        
                                                                 <cfset propAdvice.setInSchool(true) />
                                                       
                                                                 <!--- 
                                                                      $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
                                                                      可选属性 
                                                                      $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
                                                                 --->
                                                                 
                                                                 <!---是否本科--->
                                                                 <cfset isBachelor = "0" />
                                                                 <cfif stuType eq "8">
                                                                      <cfset isBachelor = "1" />
                                                                 </cfif>
                                                                 
                                                                 <cfset joinDate = "" />
                                                                 <cfset homeAddress = "" />
                                                                 <cfset ptDate = "" />
                                                                 <cfset isMarried = "" />
                                                                 <cfset chAddr = "" />
                                                                 <cfset email = "" />
                                                                 <cfset tel = "" />
                                                                 <cfset funds = "" />
                                                                 
                                                                 <!--- 入学日期 --->
                                                                 <cfif listFindNoCase(rs.columnList, "入学日期") and len(rs["入学日期"][rs.currentRow])>
                                                                           <cfset joinDate = left(rs["入学日期"][rs.currentRow],4) & "-" & mid(rs["入学日期"][rs.currentRow],5,2) & "-" & right(rs["入学日期"][rs.currentRow],2) />
                                                                 </cfif>
                                                           
                                                                 <!--- 家庭住址 --->
                                                                 <cfif listFindNoCase(rs.columnList, "家庭住址") and len(rs["家庭住址"][rs.currentRow])>
                                                                           <cfset homeAddress = rs["家庭住址"][rs.currentRow] />
                                                                 </cfif>
                                                       
                                                                  <!--- 护照有效期 --->
                                                                 <cfif listFindNoCase(rs.columnList, "护照有效期") and len(rs["护照有效期"][rs.currentRow])>
                                                                           <cfset ptDate = left(rs["护照有效期"][rs.currentRow],4) & "-" & mid(rs["护照有效期"][rs.currentRow],5,2) & "-" & right(rs["护照有效期"][rs.currentRow],2) />
                                                                 </cfif>
                                                                 
                                                               
                                                                 
                                                                   <!--- 婚姻状况 --->
                                                                 <cfif listFindNoCase(rs.columnList, "婚姻状况")and len(rs["婚姻状况"][rs.currentRow]) >
                                                                 
                                                                      <cfif rs["婚姻状况"][rs.currentRow] eq "已婚">
                                                                           <cfset isMarried = "1" />
                                                                      <cfelse>
                                                                           <cfset isMarried = "0" />
                                                                      </cfif>
                                                                 </cfif>
                                                                 
                                                                 <!--- 在华住址  --->
                                                                 <cfif listFindNoCase(rs.columnList, "在华住址") and len(rs["在华住址"][rs.currentRow])>
                                                                           <cfset chAddr = rs["在华住址"][rs.currentRow] />
                                                                 </cfif>
                                                                 
                                                                 <!--- 邮件  --->
                                                                 <cfif listFindNoCase(rs.columnList, "邮件") and len(rs["邮件"][rs.currentRow])>
                                                                           <cfset email = rs["邮件"][rs.currentRow] />
                                                                 </cfif>
                                                                 
                                                                 <!--- 电话  --->
                                                                 <cfif listFindNoCase(rs.columnList, "电话") and len(rs["电话"][rs.currentRow])>
                                                                           <cfset tel = rs["电话"][rs.currentRow] />
                                                                 </cfif>
                                                                 
                                                                 <!--- 经费来源  --->
                                                                 <cfif listFindNoCase(rs.columnList, "经费来源") and len(rs["经费来源"][rs.currentRow]) >
                                                                 
                                                                           <cfset sql = "SELECT code_id FROM i_code_info WHERE name = :typeName AND field_id = '3' " /> 
                              
                                                                           <cfset queryObj = new Query( datasource=application.dnsMaster ) />
                                                                           
                                                                           <cfset queryObj.addParam( name="typeName", value=rs["经费来源"][rs.currentRow], cfsqltype="cf_sql_varchar" ) /> 
                                                                           
                                                                           <cfset rs_fundType = queryObj.execute( sql=sql ).getResult() />  
                                                                           
                                                                           <cfset funds = "" />
                                                                           
                                                                           <cfif rs_fundType.recordCount >
                                                                                <cfset funds = rs_fundType.code_id />
                                                                           </cfif>
                                                                      <cfelse>
                                                                           <cfset funds = "" />
                                                                 </cfif>
     
                                                                 <cfset StudentProps = propAdvice.stringProperty() />
     
                                                                 <!--- 创建新学籍基础数据 --->
                                                                 <cfset sql = "INSERT INTO t_student_status(
                                                                                          stu_id, institute_id, subject_code, 
                                                                                          b_id, st_id, f_id, acad_type, 
                                                                                          grade, level_code, status_code, candidatesno, 
                                                                                          student_prop, date_join, homeaddr, zipcode,
                                                                                          stu_email, stu_tel, stu_company, is_married,
                                                                                          hsk_score, ch_addr, is_bachelor, pt_date  
                                                                                     )VALUES(
                                                                                          :studentId, :instituteId, :subjectCode, 
                                                                                          :branchID, :studentTypeCode, :fosterCode, :academicType, 
                                                                                          :grade, :studentLevel, :statusCode, :candidatesNo, 
                                                                                          :studentProps, :joinDate, :homeAddress, :zipCode, 
                                                                                          :email, :stuTel, :stuCompany, :isMarried, 
                                                                                          :hskScore, :chAddr, :isBachelor, :ptDate  
                                                                                     )" /> 
                                                                 
                                                                 <cfset queryObj = new Query( datasource=application.dnsMaster ) /> 
                                                                 <cfset queryObj.addParam( name="studentId", value=trim(rs["学号"][rs.currentRow]), cfsqltype="cf_sql_varchar" ) /> 
                                                                 <cfset queryObj.addParam( name="instituteId", value='101', cfsqltype="cf_sql_varchar" ) /> 
                                                                 <cfset queryObj.addParam( name="subjectCode", value='JMHY', cfsqltype="cf_sql_char" ) /> 
                                                                 <cfset queryObj.addParam( name="branchID", value='01', cfsqltype="cf_sql_char" ) /> 
                                                                 <cfset queryObj.addParam( name="studentTypeCode", value=stuType, cfsqltype="cf_sql_varchar" ) /> 
                                                                 <cfset queryObj.addParam( name="fosterCode", value=funds, cfsqltype="cf_sql_varchar" ) /> 
                                                                 <cfset queryObj.addParam( name="academicType", value='1', cfsqltype="cf_sql_char" ) /> 
                                                                 <cfset queryObj.addParam( name="grade", value='2014', cfsqltype="cf_sql_char" ) /> 
                                                                 <cfset queryObj.addParam( name="studentLevel", value='3', cfsqltype="cf_sql_char" ) />
                                                                 <cfset queryObj.addParam( name="statusCode", value='01', cfsqltype="cf_sql_char" ) /> 
                                                                 <cfset queryObj.addParam( name="candidatesNo", value='', cfsqltype="cf_sql_varchar" ) /> 
                                                                 <cfset queryObj.addParam( name="studentProps", value=StudentProps, cfsqltype="cf_sql_varchar" ) /> 
                                                                 <cfset queryObj.addParam( name="joinDate", value=joinDate, cfsqltype="cf_sql_char" ) /> 
                                                                 <cfset queryObj.addParam( name="homeAddress", value=homeAddress, cfsqltype="cf_sql_varchar" ) />
                                                                 <cfset queryObj.addParam( name="zipCode", value='', cfsqltype="cf_sql_varchar" ) />
                                                                 <cfset queryObj.addParam( name="email", value=email, cfsqltype="cf_sql_varchar" ) />
                                                                 <cfset queryObj.addParam( name="stuTel", value=tel, cfsqltype="cf_sql_varchar" ) />
                                                                 <cfset queryObj.addParam( name="stuCompany", value='', cfsqltype="cf_sql_varchar" ) />
                                                                 <cfset queryObj.addParam( name="isMarried", value=isMarried, cfsqltype="cf_sql_varchar" ) />
                                                                 <cfset queryObj.addParam( name="hskScore", value='', cfsqltype="cf_sql_varchar" ) />
                                                                 <cfset queryObj.addParam( name="chAddr", value=chAddr, cfsqltype="cf_sql_varchar" ) />
                                                                 <cfset queryObj.addParam( name="isBachelor", value=isBachelor, cfsqltype="cf_sql_char" ) />
                                                                 <cfset queryObj.addParam( name="ptDate", value=ptDate, cfsqltype="cf_sql_varchar" ) />
                                
                                                                 <cfset queryObj.execute( sql=sql ) /> 
                                                                       
                                                                     
                                                                 <!--- 处理学生成绩统计数据 --->
                                                       
                                                                 <cfset sql = "SELECT 1 FROM t_student_profile WHERE stu_id = :studentId" />
          
                                                                 <cfset queryObj = new Query( datasource=application.dnsMaster ) />
                                                                 
                                                                 <cfset queryObj.addParam( name="studentId", value=rs["学号"][rs.currentRow], cfsqltype="cf_sql_varchar" ) />
                                                                 
                                                                 <cfset rs_studentMarkProfile = queryObj.execute( sql=sql ).getResult() />
                                                       
                                                                 <cfif rs_studentMarkProfile.recordCount EQ 0>
                                                                           <!--- 创建新学生成绩统计数据 --->
                                                                           <cfset sql = "INSERT INTO t_student_profile 
                                                                                                    (
                                                                                                         stu_id, 
                                                                                                         credit, credit_req, credit_opt, credit_phy, credit_com, credit_failure,
                                                                                                         credit_req_pt, credit_req_avgpt, 
                                                                                                         credit_pt, credit_avgpt,
                                                                                                         subject_rank, subject_idx, 
                                                                                                         subject_rank_all, subject_idx_all, 
                                                                                                         credit_grad, credit_grad_pt, credit_grad_avgpt
                                                                                                    ) 
                                                                                                    VALUES 
                                                                                                    (
                                                                                                         :studentId, 
                                                                                                         0, 0, 0, 0, 0, 0, 
                                                                                                         0, 0, 
                                                                                                         0, 0, 
                                                                                                         0, 0, 0, 0, 
                                                                                                         0, 0, 0
                                                                                                    ) " /> 
                                                                           
                                                                           <cfset queryObj = new Query( datasource=application.dnsMaster ) /> 
                                                                           
                                                                           <cfset queryObj.addParam( name="studentId", value=trim(rs["学号"][rs.currentRow]), cfsqltype="cf_sql_varchar" ) />
                                                                           
                                                                           <cfset queryObj.execute( sql=sql ) />
                                                                           
                                                                 </cfif>
                                                                 
                                                                 <cfset content =  "导入学生,新增 " & rs["护照名"][rs.currentRow] & "(" & rs["学号"][rs.currentRow] & ")  学籍信息" />
                                                                      
                                                                 <cfset logFactory.writeLog("3", content, rs["学号"][rs.currentRow]) />
                                                                 
                                                            <cfelse>
                                                                 <p class="error">学生:<cfoutput>#rs["学号"][rs.currentRow]#</cfoutput> 已经存在</p>
                                                       </cfif>
                                                                                                                   
                                                  <cfelse>
                                                       <p class="error">学生:<cfoutput>#rs["护照名"][rs.currentRow]#</cfoutput>(<cfoutput>#rs["学号"][rs.currentRow]#</cfoutput>) <cfoutput>#rs["班级"][rs.currentRow]#</cfoutput> 护照号 录入不正确</p>
                                             </cfif>
                                        <cfelse>
                                             <p class="error">学生:<cfoutput>#rs["护照名"][rs.currentRow]#</cfoutput>(<cfoutput>#rs["学号"][rs.currentRow]#</cfoutput>) 国籍 <cfoutput>#rs["国籍"][rs.currentRow]#</cfoutput> 录入不正确. 该国籍在系统中没有对应的数据记录.</p>
                                   </cfif>
								
						</cfloop> 
					 
					</cftransaction> 
					
					
					<cftransaction>
						
						<!--- 创建用户角色 --->
						<cfset ts = datetimeAdvice.getCurrentDatetimeString() />
						<cfloop query="rs">
							
                                  <cfset stuId =  trim(rs["学号"][rs.currentRow]) />
                                  <cfif stuId neq "" >
							   <cfset sql = "SELECT 1 FROM t_user WHERE user_id = :userId" />
          
                                      <cfset queryObj = new Query( datasource=application.dnsMaster ) />
                                             
                                      <cfset queryObj.addParam( name="userId", value=stuId, cfsqltype="cf_sql_varchar" ) />
                                      
                                      <cfset rs_user = queryObj.execute( sql=sql ).getResult() />
                                        
                                      <cfif rs_user.recordCount EQ 0>
                                             <!--- 创建新帐号基础数据 --->
                                          <cfset sql = "INSERT INTO t_user (
                                                                           user_id, user_name, user_email,
                                                                           user_last_login, user_last_login_ip, user_pass,user_login  
                                                                      )VALUES(
                                                                           :uid, :name, :email, 
                                                                           :lastTimeLogin, :lastTimeIP, :userPass, :userLogin 
                                                                      )" /> 
                                          
                                          <cfset queryObj = new Query( datasource=application.dnsMaster ) /> 
                                          <cfset queryObj.addParam( name="uid", value=trim(rs["学号"][rs.currentRow]), cfsqltype="cf_sql_varchar" ) />
                                          <cfset queryObj.addParam( name="name", value=rs["护照名"][rs.currentRow], cfsqltype="cf_sql_varchar" ) />
                                          <cfset queryObj.addParam( name="email", value=rs["学号"][rs.currentRow] & "@unknow.email", cfsqltype="cf_sql_varchar" ) />
                                          <cfset queryObj.addParam( name="lastTimeLogin", value=ts, cfsqltype="cf_sql_char" ) />
                                          <cfset queryObj.addParam( name="lastTimeIP", value="127.0.0.1", cfsqltype="cf_sql_varchar" ) />
                                          <cfset queryObj.addParam( name="userPass", value="000000", cfsqltype="cf_sql_varchar" ) />
                                           <cfset queryObj.addParam( name="userLogin", value=trim(rs["学号"][rs.currentRow]), cfsqltype="cf_sql_varchar" ) />
                                          
                                          
                                          <cfset queryObj.execute( sql=sql ) />
                                     
                                        </cfif>
                                        
                                  </cfif>
							
						</cfloop>
						
						<cfloop query="rs">
							
                                  <cfset stuId =  trim(rs["学号"][rs.currentRow]) />
                                   <cfif stuId neq "" >
							   <cfset sequenceMatrixGroupUser.setUserId(rs["学号"][rs.currentRow]) />
                                      <cfset sequenceMatrixGroupUser.setGroupId("P002") />
                                      <cfset userGroupId = sequenceMatrixGroupUser.getID() />
                                                                      
                                      <cfset sql = "SELECT 1 FROM t_groupuser WHERE ugid = :userGroupID" />
          
                                      <cfset queryObj = new Query( datasource=application.dnsMaster ) />
                                      <cfset queryObj.addParam( name="userGroupID", value=userGroupId, cfsqltype="cf_sql_varchar" ) />
                                      
                                      <cfset rs_userGroupCheck = queryObj.execute( sql=sql ).getResult() />
                                        
                                      <cfif rs_userGroupCheck.recordCount EQ 0 >
                                             
                                          <cfset sql = "INSERT INTO t_groupuser (
                                                                           user_id, group_id, ugid,
                                                                           date_create, date_lastupdate
                                                                      )VALUES(
                                                                           :userId, :groupId, :userGroupID, 
                                                                           :created, :lastUpdate 
                                                                      )" /> 
                                          
                                          <cfset queryObj = new Query( datasource=application.dnsMaster ) /> 
                                          <cfset queryObj.addParam( name="userId", value=rs["学号"][rs.currentRow], cfsqltype="cf_sql_varchar" ) />
                                          <cfset queryObj.addParam( name="groupId", value="P002", cfsqltype="cf_sql_char" ) />
                                          <cfset queryObj.addParam( name="userGroupID", value=userGroupId, cfsqltype="cf_sql_varchar" ) />
                                          <cfset queryObj.addParam( name="created", value=ts, cfsqltype="cf_sql_char" ) />
                                          <cfset queryObj.addParam( name="lastUpdate", value=ts, cfsqltype="cf_sql_char" ) />
                                          
                                          <cfset queryObj.execute( sql=sql ) />
                                     
                                        </cfif>
                                      
                                    </cfif>
                                        
						</cfloop>
						
					</cftransaction>
						
				</cfif>
			</cfif>
		</cfif> 
		
		<p>新增学籍数据 [<cfoutput>#studentInsert#</cfoutput>] 条.</p>
		
		<a target="_parent" href="<cfoutput>#buildURL('studentByHeadTeacher')#</cfoutput>">刷新学籍数据</a>
		
		<!--- 删除临时文件 --->
		<cfif fileExists(temFile)>
			<cffile action="delete" file="#temFile#" />		
		</cfif>
	
	</cfif>

</body>
</html>